from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand

from models.admin import Admin
from models.base import db
from models.user import User
from models.category import Category
from models.item import Item


from app import create_app
app = create_app()
with app.app_context():
    manager = Manager(app=app)
    Migrate(app=app, db=db)
    manager.add_command('db', MigrateCommand)


@manager.command
def create_cate():
    cate = Category()
    cate.name = '其他'
    cate.url = 'http://www.neea.edu.cn/html1/category/1705/2978-1.htm'
    with db.auto_commit():
        db.session.add(cate)


@manager.command
def create_item():
    item = Item()
    item.name = '成人高考'
    item.url = 'http://chengkao.neea.edu.cn/'
    item.category_id = 1
    with db.auto_commit():
        db.session.add(item)


@manager.command
def create_admin():
    admin = Admin()
    admin.username = 'admin'
    admin.password = '111111'
    with db.auto_commit():
        db.session.add(admin)



if __name__ == '__main__':
    manager.run()
